package com.lili.operate.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.lili.common.result.Result;
import com.lili.model.operate.CustomWords;
import com.lili.operate.service.CustomWordsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("/admin")
@Api(tags = "分词管理模块")
public class WordsController {
    @Autowired
    CustomWordsService customWordsService;

    @ApiOperation("删除分词")
    @DeleteMapping("/delete/custom/words")
    public Result deleteCustomWords(long id){
        int rs = customWordsService.deleteCustomWords(id);
        return rs==1?Result.ok():Result.fail();
    }

    @ApiOperation("查询素有的分词")
    @PostMapping("/query/custom/words")
    public Result queryCustomWords(@RequestBody Map map){
        Page<CustomWords> page = customWordsService.queryCustomWords(map);
        return page ==null?Result.fail():Result.ok(page);
    }

    @ApiOperation("更新分词内容")
    @PostMapping("/update/custom/words")
    public Result updateCustomWords(@RequestBody Map map){
        long id = Long.parseLong(map.get("id").toString());
        String name = map.get("name").toString();
        int rs = customWordsService.updateCustomWords(name,id);
        return rs==1?Result.ok():Result.fail();
    }
    @ApiOperation("新增分词")
    @PostMapping("/save/custom/words")
    public Result saveCustomWords(@RequestBody CustomWords customWords){
        int rs = customWordsService.saveCustomWords(customWords);
        return rs==1?Result.ok():Result.fail();
    }
}
